{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 工程文件说明"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "| AB榜 | 文件 | 说明 | 执行时间 | 执行顺序 |\n",
    "| :---: | :---: | :---: | :---: | :---: |\n",
    "|  | feature | 文件夹，存放特征文件 |  |  |\n",
    "|  | tmp | 文件夹，存放程序生成的临时文件 |  |  |\n",
    "| A榜 | A1.特征工程_HJJ_A榜.ipynb | 特征工程文件1 | 约2小时 | 1 |\n",
    "| A榜 | A2.特征工程_LYH_A榜.ipynb | 特征工程文件2 | 约2小时 | 1 |\n",
    "| A榜 | A3.特征工程_YXH_A榜.ipynb | 特征工程文件3 | 约1小时 | 1 |\n",
    "| A榜 | A4.模型_LGB_A榜.ipynb  | LGB模型文件 | 约20分钟 | 2 |\n",
    "| A榜 | A5.模型_CAT_A榜.ipynb  | CAT模型文件 | 约10分钟 | 3 |\n",
    "| B榜 | B1.特征工程_HJJ_B榜.ipynb  | 特征工程文件1 | 约2小时 | 1 |\n",
    "| B榜 | B2.特征工程_LYH_B榜.ipynb  | 特征工程文件2 | 约2小时 | 1 |\n",
    "| B榜 | B3.特征工程_YXH_B榜.ipynb  | 特征工程文件3 | 约1小时 | 1 |\n",
    "| B榜 | B4.模型_LGB_B榜.ipynb  | LGB模型文件 | 约20分钟 | 2 |\n",
    "| B榜 | B3.特征工程_YXH_B榜.ipynb  | CAT模型文件 | 约10分钟 | 3 |\n",
    "|  | 说明文档.ipynb | 说明文档 |  |  |\n",
    "|  | 答案A榜.csv | A榜答案 |  |  |\n",
    "|  | 答案B榜.csv | B榜答案 |  |  |\n",
    "|  | utils.py | 一些函数定义 |  |  |"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 特征工程"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 掌银金融性流水表（MBANK_TRNFLW_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T02:02:01.657517Z",
     "iopub.status.busy": "2023-11-07T02:02:01.657243Z",
     "iopub.status.idle": "2023-11-07T02:02:01.664809Z",
     "shell.execute_reply": "2023-11-07T02:02:01.664057Z",
     "shell.execute_reply.started": "2023-11-07T02:02:01.657487Z"
    },
    "tags": []
   },
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分组特征\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易频数的'mean', 'sum', 'median', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易金额的'mean', 'sum', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易代码的'count', 'nunique'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照总/月/天统计交易对手账号的'count', 'nunique'；"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 滑窗特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 滑窗交易频数统计：近2周/近4周/近6周/近8周的频数、间隔及与全量之比；\n",
    "\n",
    "* 滑窗交易金额统计：近2周/近4周/近6周/近8周的金额与与交易总金额之比；\n",
    "\n",
    "* 根据客户号和标准业务代码进行分组，分别按照年/月/周统计交易金额的'mean','max','min','median','std','sum','count'；\n",
    "\n",
    "* 根据交易账号/交易对手账号和标准业务代码进行分组，分别按照年/月/周统计交易频数的nunique','count'；"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 掌银非金融性流水表（MBANK_QRYTRNFLW_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分组特征\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易频数的'mean', 'sum', 'median', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易代码的'count', 'nunique'；\n",
    "\n",
    "* 根据交易账号和标准业务代码进行分组，分别按照年/月/周统计交易频数的nunique','count'；\n",
    "\n",
    "### 滑窗特征\n",
    "\n",
    "* 滑窗交易频数统计：近2周/近4周/近6周/近8周的频数、间隔及与全量之比例；\n",
    "\n",
    "### 文本特征\n",
    "\n",
    "* 提取该表CLQ_BSNCOD业务代码的词频和词袋特征；\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 网银金融性流水表（EBANK_CSTLOG_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分组特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 根据客户号进行分组，分别按照年/月/天统计交易频数的'mean', 'sum', 'median', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易金额的'mean', 'sum', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易代码的'count', 'nunique'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照总/月/天统计交易对手账号的'count', 'nunique'；\n",
    "\n",
    "* 根据交易账号/交易对手账号和标准业务代码进行分组，分别按照年/月/周统计交易频数的nunique','count'；"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 滑窗特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 滑窗交易频数统计：近2周/近4周/近6周/近8周的频数、间隔及与全量之比；\n",
    "\n",
    "* 滑窗交易金额统计：近2周/近4周/近6周/近8周的金额与与交易总金额之比；\n",
    "\n",
    "* 根据客户号和标准业务代码进行分组，分别按照年/月/周统计交易金额的'mean','max','min','median','std','sum','count'；"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T02:10:24.436630Z",
     "iopub.status.busy": "2023-11-07T02:10:24.436355Z",
     "iopub.status.idle": "2023-11-07T02:10:24.439491Z",
     "shell.execute_reply": "2023-11-07T02:10:24.438883Z",
     "shell.execute_reply.started": "2023-11-07T02:10:24.436601Z"
    },
    "tags": []
   },
   "source": [
    "## 网银非金融性流水表（EBANK_CSTLOGQUERY_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分组特征\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易频数的'mean', 'sum', 'median', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易代码的'count', 'nunique'；\n",
    "\n",
    "* 根据交易账号和标准业务代码进行分组，分别按照年/月/周统计交易频数的nunique','count'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易代码的'count', 'nunique'；\n",
    "\n",
    "### 滑窗特征\n",
    "\n",
    "* 滑窗交易频数统计：近2周/近4周/近6周/近8周的频数、间隔及与全量之比例；\n",
    "\n",
    "### 文本特征\n",
    "\n",
    "* 提取该表CLQ_BSNCOD业务代码的词频和词袋特征；\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 借记卡交易流水表（APS_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 文本特征\n",
    "\n",
    "* 拼接交易对手账号、交易代码、交易渠道等成文本序列，提取文本特征TF-IDF（词频-逆文件频率）、CountVectorizer(词频)和Word2Vec(词向量)；\n",
    "\n",
    "### 分组特征\n",
    "\n",
    "* 分别根据账号分组、账号与交易代码分组、账号与交易渠道分组，统计交易金额、月份、日期、小时、分钟、星期、间隔天数等'mean','max','min','median','std','skew','ptp','sum','count'等统计量；\n",
    "\n",
    "* 分别根据账号与交易代码分组、账号与交易渠道分组，统计交易对手账号个数；\n",
    "\n",
    "* 根据账号与交易渠道分组，统计各交易渠道交易次数及占比；\n",
    "\n",
    "* 根据账号与交易代码分组，统计各交易代码交易次数及占比；\n",
    "\n",
    "* 根据账号分组，统计交易对手账号、交易代码、交易渠道等种类数，按月统计交易对手账号数量和交易次数，统计交易间隔小时数的'mean','max','min','median','std'等统计量，统计每日交易金额的'mean','max','min','median','std','skew','sum'等统计量，按月、按最近一周统计每日流入流出交易金额及占比，按天、按月统计账号的日交易小时数；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易频数的'mean', 'sum', 'median', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易金额的'mean', 'sum', 'max','min', 'skew', 'std'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照年/月/天统计交易代码的'count', 'nunique'；\n",
    "\n",
    "* 根据客户号进行分组，分别按照总/月/天统计交易对手账号的'count', 'nunique'；\n",
    "\n",
    "### 图谱特征\n",
    "\n",
    "* 利用账号和交易对手账号构建关系图谱，通过Louvain 算法预测账号所属社区，计算点度中心性、特征值中心性等中心性度量数据；\n",
    "\n",
    "### 滑窗特征\n",
    "\n",
    "* 按照距今交易月数、距今交易周数、距今天数等维度，账号分组统计日交易金额、日交易笔数、日交易代码数、日交易渠道数等；\n",
    "\n",
    "* 从第二个月开始，取7日前对手交易，比对出近7陌生交易对手列表，统计单日陌生交易金额、单日陌生交易对手数和单日陌生交易笔数等；\n",
    "\n",
    "* 区分空交易对手流水，按日/星期/月滑窗，统计日交易金额、日交易笔数、日交易代码数、日交易渠道数等\n",
    "\n",
    "* 分别从0点-6点、6点-18点、18点-06点等三个时间段统计交易金额、交易次数等；\n",
    "\n",
    "* 滑窗交易频数统计：近2周/近4周/近6周/近8周的频数、间隔及与全量之比；\n",
    "\n",
    "* 滑窗转入金额统计：近2周/近4周/近6周/近8周的金额与与转入总金额之比；\n",
    "\n",
    "* 滑窗转出金额统计：近2周/近4周/近6周/近8周的金额与与转入总金额之比；"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T07:02:39.414655Z",
     "iopub.status.busy": "2023-11-07T07:02:39.414377Z",
     "iopub.status.idle": "2023-11-07T07:02:39.418917Z",
     "shell.execute_reply": "2023-11-07T07:02:39.418205Z",
     "shell.execute_reply.started": "2023-11-07T07:02:39.414621Z"
    }
   },
   "source": [
    "### 业务特征\n",
    "#### 等额高频交易\n",
    "* 计算等额交易大于五次的次数，并统计量mean、max、sum、count\n",
    "\n",
    "#### 快进快出\n",
    "* 计算客户在一个小时内是否有快进快出，及快进快出的借方总额，贷方总额\n",
    "\n",
    "#### 近N天陌生陌生交易对手个数\n",
    "* 计算客户最近1、4、7、10、13的陌生交易对手个数\n",
    "\n",
    "#### 夜间交易对手\n",
    "* 计算客户的夜间交易对手个数，夜间交易金额量，夜间交易贷方总金额，夜间交易借方总金额\n",
    "\n",
    "#### 计算日借贷方特征\n",
    "* 计算客户日交易小时数、日借方交易额/贷方交易额、日借贷交易金额比、日贷方交易金额、日借方交易金额、日净交易金额\n",
    "\n",
    "#### 计算小额测试\n",
    "* 计算客户小额测试的总次数\n",
    "\n",
    "#### 单日N笔交易以上天数\n",
    "* 计算客户单日5、10、15、20、25、30、35、40、45、50笔以上的天数\n",
    "\n",
    "#### 取现交易\n",
    "* 计算空交易对手的交易码的统计量，猜测理财/定期/JICS临冻/取现理财/定期/JICS临冻/取现有关"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 客户金融资产信息表（CUST_FA_SUM_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T01:15:48.146215Z",
     "iopub.status.busy": "2023-11-07T01:15:48.145916Z",
     "iopub.status.idle": "2023-11-07T01:15:48.199336Z",
     "shell.execute_reply": "2023-11-07T01:15:48.198639Z",
     "shell.execute_reply.started": "2023-11-07T01:15:48.146178Z"
    }
   },
   "source": [
    "###  交叉特征\n",
    "* 对表内全部特征做交叉减除衍生特征\n",
    "\n",
    "###  源表特征\n",
    "* 对原始数据无修改，原始字段特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 客户定活期存款信息表（DP_CUST_SUM_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 交叉特征\n",
    "* 客户金融资产信息表（CUST_FA_SUM_QZ）和客户定活期存款信息表（DP_CUST_SUM_QZ）一起处理。\n",
    "\n",
    "AUM/金融资产（包括当日/月日均/季日均/年日均）、活期存款/AUM（包括当日/月日均/季日均/年日均）、定期存款/AUM（包括当日/月日均/季日均/年日均）、金融资产/总投资（包括当日/月日均/季日均/年日均）、金融资产-AUM(贷款)/金融资产（包括当日/月日均/季日均/年日均）、活期+定期/aum（包括当日/月日均/季日均/年日均）、当日AUM-（月日均/季日均/年日均）AUM之比、当日存款-（月日均/季日均/年日均）存款之比AUM/金融资产（包括当日/月日均/季日均/年日均）、活期存款/AUM（包括当日/月日均/季日均/年日均）、定期存款/AUM（包括当日/月日均/季日均/年日均）、金融资产/总投资（包括当日/月日均/季日均/年日均）、金融资产-AUM(贷款)/金融资产（包括当日/月日均/季日均/年日均）、活期+定期/aum（包括当日/月日均/季日均/年日均）、当日AUM-（月日均/季日均/年日均）AUM之比、当日存款-（月日均/季日均/年日均）存款之比### 交叉特征\n",
    "客户金融资产信息表（CUST_FA_SUM_QZ）和客户定活期存款信息表（DP_CUST_SUM_QZ）一起处理。\n",
    "\n",
    "AUM/金融资产（包括当日/月日均/季日均/年日均）、活期存款/AUM（包括当日/月日均/季日均/年日均）、定期存款/AUM（包括当日/月日均/季日均/年日均）、金融资产/总投资（包括当日/月日均/季日均/年日均）、金融资产-AUM(贷款)/金融资产（包括当日/月日均/季日均/年日均）、活期+定期/aum（包括当日/月日均/季日均/年日均）、当日AUM-（月日均/季日均/年日均）AUM之比、当日存款-（月日均/季日均/年日均）存款之比AUM/金融资产（包括当日/月日均/季日均/年日均）、活期存款/AUM（包括当日/月日均/季日均/年日均）、定期存款/AUM（包括当日/月日均/季日均/年日均）、金融资产/总投资（包括当日/月日均/季日均/年日均）、金融资产-AUM(贷款)/金融资产（包括当日/月日均/季日均/年日均）、活期+定期/aum（包括当日/月日均/季日均/年日均）、当日AUM-（月日均/季日均/年日均）AUM之比、当日存款-（月日均/季日均/年日均）存款之比\n",
    "\n",
    "### 源表特征\n",
    "* 对原始数据无修改，原始字段特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 自然属性表（NATURE_CUST_QZ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "备注：A榜B榜通用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 编码处理\n",
    "* 客户性别进行unique编码，客户等级进行one-hot编码，其次性别、等级再进行目标编码。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 源表特征\n",
    "* 不做处理，原始数据作为特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T07:17:50.686125Z",
     "iopub.status.busy": "2023-11-07T07:17:50.685829Z",
     "iopub.status.idle": "2023-11-07T07:17:50.689936Z",
     "shell.execute_reply": "2023-11-07T07:17:50.689231Z",
     "shell.execute_reply.started": "2023-11-07T07:17:50.686097Z"
    }
   },
   "source": [
    "## 客户产品持有表（TAGS_PROD_HOLD_QZ）\n",
    "### 源表特征\n",
    "* 不做处理，原始数据作为特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 特征筛选(AB榜通用)\n",
    "将上述加工完成特征进行合并，列数达4455列，特征数据过多，采取合适的方式进行特征筛选\n",
    "\n",
    "## 空值筛选\n",
    "* 筛选掉空值占比达98%的特征\n",
    "\n",
    "## 相关性筛选\n",
    "* 筛选掉共线性高的特征\n",
    "\n",
    "## 唯一性筛选\n",
    "* 筛选掉唯一值为1个的列\n",
    "\n",
    "## 对抗性验证\n",
    "* 筛选掉训练与验证集分布差异高的列\n",
    "\n",
    "## null_important筛选\n",
    "* 筛选掉对模型重要性低的特征\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A榜\n",
    "\n",
    "采用两个模型 LGB与CAT 两个模型进行训练\n",
    "### LGB\n",
    "\n",
    "采用4个随机种子[1993,2008,4096,1015]，五折交叉验证进行训练，入模特征维度为379\n",
    "\n",
    "参数如下\n",
    "parameters = {\n",
    "    'learning_rate': 0.01,  #\n",
    "    'max_depth': -1,#-1\n",
    "    'boosting_type': 'gbdt',\n",
    "    'objective': 'binary',\n",
    "    'metric': ['auc','binary_logloss','binary_error'],\n",
    "    'num_leaves': 12, #'num_leaves': 15, \n",
    "    'feature_fraction': 0.8,\n",
    "    'bagging_fraction': 0.8,\n",
    "    'bagging_freq': 5,\n",
    "    'seed': 2021,\n",
    "    # 'lambda_l2': 1,\n",
    "    'bagging_seed': 1,\n",
    "    'feature_fraction_seed': 7,\n",
    "    'min_data_in_leaf': 20,  #\n",
    "    'verbose': -1, \n",
    "    'n_jobs':8\n",
    "}\n",
    "\n",
    "### CAT\n",
    "采用一个随机种子，五折交叉验证进行训练，入模特征数为767\n",
    "参数如下\n",
    "model = CatBoostClassifier(\n",
    "    loss_function = \"Logloss\",\n",
    "    eval_metric = \"AUC\",\n",
    "    learning_rate = 0.05,\n",
    "    iterations = 1000,\n",
    "    random_seed = 42,\n",
    "    verbose = 100,\n",
    "    early_stopping_rounds = 200,\n",
    "    depth = 3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## B榜：\n",
    "采用两个模型 LGB与CAT 两个模型进行训练采用两个模型 LGB与CAT 两个模型进行训练\n",
    "\n",
    "### LGB\n",
    "采用1个随机种子，五折交叉验证进行训练，入模特征维度为1067\n",
    "\n",
    "参数如下\n",
    "parameters = {\n",
    "    'learning_rate': 0.02,  #0.03：0.6155,0.02:0.6153\n",
    "    'max_depth': -1,#-1\n",
    "    'boosting_type': 'gbdt',\n",
    "    'objective': 'binary',\n",
    "    'metric': ['auc','binary_logloss','binary_error'],\n",
    "    'num_leaves': 12, #'num_leaves': 15, \n",
    "    'feature_fraction': 0.8,\n",
    "    'bagging_fraction': 0.8,\n",
    "    'bagging_freq': 5,\n",
    "    'seed': 2021,\n",
    "    # 'lambda_l2': 1,\n",
    "    'bagging_seed': 1,\n",
    "    'feature_fraction_seed': 7,\n",
    "    'min_data_in_leaf': 20,  #\n",
    "    'verbose': -1, \n",
    "    'n_jobs':8\n",
    "}parameters = {\n",
    "    'learning_rate': 0.02,  #0.03：0.6155,0.02:0.6153\n",
    "    'max_depth': -1,#-1\n",
    "    'boosting_type': 'gbdt',\n",
    "    'objective': 'binary',\n",
    "    'metric': ['auc','binary_logloss','binary_error'],\n",
    "    'num_leaves': 12, #'num_leaves': 15, \n",
    "    'feature_fraction': 0.8,\n",
    "    'bagging_fraction': 0.8,\n",
    "    'bagging_freq': 5,\n",
    "    'seed': 2021,\n",
    "    # 'lambda_l2': 1,\n",
    "    'bagging_seed': 1,\n",
    "    'feature_fraction_seed': 7,\n",
    "    'min_data_in_leaf': 20,  #\n",
    "    'verbose': -1, \n",
    "    'n_jobs':8\n",
    "}\n",
    "\n",
    "### CAT\n",
    "采用一个随机种子，五折交叉验证进行训练，入模特征数为1124\n",
    "\n",
    "model = CatBoostClassifier(\n",
    "    loss_function = \"Logloss\",\n",
    "    eval_metric = \"AUC\",\n",
    "    learning_rate = 0.01,\n",
    "    iterations = 2000,\n",
    "    random_seed = 142,\n",
    "    verbose = 100,\n",
    "    early_stopping_rounds = 200,\n",
    "    depth = 5,\n",
    "     reg_lambda = 2\n",
    ")model = CatBoostClassifier(\n",
    "    loss_function = \"Logloss\",\n",
    "    eval_metric = \"AUC\",\n",
    "    learning_rate = 0.01,\n",
    "    iterations = 2000,\n",
    "    random_seed = 142,\n",
    "    verbose = 100,\n",
    "    early_stopping_rounds = 200,\n",
    "    depth = 5,\n",
    "     reg_lambda = 2\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 模型融合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 线性回归（AB榜通用）\n",
    "\n",
    "对存款表，资产表，客户产品持有表，和加总表分别训练了4个LR模型，共八个特征加入到总的特征矩阵中\n",
    "\n",
    "## A榜，加权融合\n",
    "以LGB*0.7+CAT*0.3的比例进行预测概率加权融合\n",
    "\n",
    "## B榜，stacking\n",
    "* 将LGB训练出来的概率作为CAT的一个新特征，进行训练\n",
    "\n",
    "* 设定一个规则模型，将CAT的结果与规则模型进行投票融合\n",
    "\n",
    "规则模型：\n",
    "转账笔数： 最近七天转入转出笔数比介于0.8和1.1\n",
    "夜晚交易对手： 晚上交易对手数量大于10\n",
    "陌生交易对手： 最近四天陌生交易对手大于3， 最近13天陌生交易对手大于6\n",
    "小额测试： 小额测试笔数大于20笔\n",
    "产品持有数量： 小于8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc-autonumbering": true
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
